﻿<cfcomponent displayname="Badges" hint="Badges">
    <cfscript>
        this.BadgeDirectory = '\\scfappshare\ITS_Data\IDCentre\BadgePhotos\';
        this.DL = 'SCF NO ONE'; 
    </cfscript>
    
    
    <cffunction name="init" access="public" returntype="Badges" output="false">
        <cfargument name="BadgeDirectory" type="string" required="no" default="\\scfappshare\ITS_Data\IDCentre\BadgePhotos\">        
        <cfscript>
            setBadgeDirectory(arguments.BadgeDirectory);
            return this;             
        </cfscript>
    </cffunction>
    
    
    <cffunction name="setDL" access="public" output="false" returntype="void">
        <cfargument name="DL" type="string" required="true" />
        <cfscript>                        
            this.DL = arguments.DL;             
        </cfscript>
        <cfreturn />
    </cffunction>
    
    
    <cffunction name="getDL" access="public" output="false" returntype="string">
        <cfreturn this.DL />
    </cffunction>
    
    
    <cffunction name="setBadgeDirectory" access="public" output="false" returntype="void">
        <cfargument name="BadgeDirectory" type="string" required="true" />
        <cfscript>                        
            this.BadgeDirectory = arguments.BadgeDirectory;             
        </cfscript>
        <cfreturn />
    </cffunction>
    
    
    <cffunction name="getBadgeDirectory" access="public" output="false" returntype="string">
        <cfreturn this.BadgeDirectory />
    </cffunction>
    
    
    <cffunction access="public" name="getBadgePicList" returntype="any">
        <cfdirectory action="list" directory="#getBadgeDirectory()#" filter="*.jpg" name="picList" >
        <cfreturn picList />
    </cffunction>
    
    
    <cffunction access="public" name="getBadgeThumbList" returntype="any">
        <cfdirectory action="list" directory="#getBadgeDirectory()#\thumbs" filter="*.jpg" name="picList" >
        <cfreturn picList />
    </cffunction>
    
    
    <cffunction access="public" name="makeBadgePicThumbs" returntype="any">
        <cfargument name="BadgePicQry" required="no" default="">
        <cfif !DirectoryExists("#getBadgeDirectory()#\thumbs")>
            <cfdirectory action="create" name="thumbDir" directory="#getBadgeDirectory()#\thumbs\" >
        </cfif>
        <cfloop query="arguments.BadgePicQry">        
            <cftry>
            	<cfset bp = getBadgeDirectory() & "\" & arguments.BadgePicQry.name />
                <cfset bpt = getBadgeDirectory() & "\thumbs\" & arguments.BadgePicQry.name />
                <cfif !FileExists(bpt) >
    	            <cffile action="readBinary" file="#bp#" variable="CopyOfPic"  />
    	            <cfimage action="resize" width="30%" height="30%" source="#CopyOfPic#" name="thumb"  />
    	            <cfimage action="write" source="#thumb#" destination="#getBadgeDirectory()#\thumbs\#arguments.BadgePicQry.name#" overwrite="no"/>
                </cfif>
            <cfcatch type="Any" >
            </cfcatch>
            </cftry>              
        </cfloop>
    </cffunction>
    
    
    <cffunction access="public" name="makeBadgeThumb" returntype="any">
        <cfargument name="Badge" required="no" default="">
        <cfif !DirectoryExists("#getBadgeDirectory()#\thumbs")>
            <cfdirectory action="create" name="thumbDir" directory="#getBadgeDirectory()#\thumbs\" >
        </cfif>      
            <cftry>
                <cfset bp = getBadgeDirectory() & "\" & arguments.Badge />
                <cfset bpt = getBadgeDirectory() & "\thumbs\" & arguments.Badge />
                <cfif !FileExists(bpt) >
                    <cffile action="readBinary" file="#bp#" variable="CopyOfPic"  />
                    <cfimage action="resize" width="30%" height="30%" source="#CopyOfPic#" name="thumb"  />
                    <cfimage action="write" source="#thumb#" destination="#getBadgeDirectory()#\thumbs\#arguments.Badge#" overwrite="no"/>
                </cfif>
            <cfcatch type="Any" >
            </cfcatch>
            </cftry>
    </cffunction>
    
    
    <cffunction access="public" name="getEmployeeBadge" returntype="any">
        <cfargument name="RosettaID" required="yes" default="0">
        <cfquery datasource="RosettaStone" name="getEmployeeBadgePic">
            SELECT     
                r.UserAccount, r.WFC_PersonID, r.HRProd_PersonIDNo, r.Fundware_EmpNo, b.RosettaID,  
                b.BadgeNumber, b.PhotoFileName, b.NumberOfCardsIssued, k.PersonIdNo, 
                k.FirstName, k.LastName, k.Department, k.Title
            FROM         
                RosettaStone AS r INNER JOIN
                Badge_IDWorks.dbo.Badges AS b ON r.RosettaID = b.RosettaID INNER JOIN
                SCFVM18.WFCSuite.dbo.CURRENT_EMPLOYEES AS k ON k.PersonIdNo = r.HRProd_PersonIDNo
            WHERE     
                (r.Disabled = 0) AND 
                (b.RosettaID = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.RosettaID#" />)
            ORDER BY b.RosettaID
        </cfquery>
        <cfreturn getEmployeeBadgePic />
    </cffunction>
    
    
    
    <cffunction access="public" name="syncBadgeAndThumbs" returntype="any">
        
    </cffunction>
    
    
</cfcomponent>